﻿using System;
using System.Windows;
using mmUI.ViewModels;

namespace mmUI.Windows
{
    /// <summary>
    /// Interaction logic for SettingsWindow.xaml
    /// </summary>
    public partial class SettingsWindow : Window
    {
        public SettingsWindow()
        {
            InitializeComponent();

            try
            {
                DataContext = new SettingsWindowVm(Dispatcher);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Initialization error:\r\n\r\n{0}",
                   ex), "MovieManager", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
        {
            var vm = DataContext as SettingsWindowVm;
            if (vm == null) return;

            vm.Password = _mPassword.Password;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var vm = DataContext as SettingsWindowVm;
            if (vm == null) return;

            if(!string.IsNullOrEmpty(vm.Password))
            {
                _mPassword.Password = vm.Password;
            }
        }
    }
}
